<template>
  <div class="container">
    <img src="@/assets/image/login1.png" alt="" />
    <div class="contentText">
      <img src="@/assets/image/logo.png" alt="" />
      <div class="title">晟艺轩拍卖平台</div>
      <div class="form">
        <van-form @submit="onSubmit">
          <van-field
            v-model="form.info.username"
            name="phone"
            left-icon="contact"
            placeholder="用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="form.info.password"
            type="password"
            name="passwd"
            left-icon="goods-collect-o"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
          <div style="margin: 16px">
            <van-button
              class="myButton"
              round
              block
              type="info"
              native-type="submit"
              >提交</van-button
            >
          </div>
        </van-form>
      </div>
      <div class="text" @click="$emit('navGetTo', 1)">没有账号？ 立即注册</div>
      <div class="text" @click="$emit('navGetTo', 2)">忘记密码</div>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive } from "vue";
import { useRoute, useRouter } from "vue-router";
import { setSignIn, getInfo } from "@/api/http.js";
import { Toast } from "vant";

export default defineComponent({
  setup() {
    const route = useRoute();
    const router = useRouter();
    const form = reactive({
      info: {
        phone: "",
        passwd: "",
      },
    });
    const onSubmit = async (values) => {
      console.log("submit---", values);
      const data = await setSignIn(values);
      if (data.code == 200) {
        Toast.success(data.msg);
        localStorage.setItem("token", data.data);
        getUserInfo();
        router.push({
          name: "Index",
        });
      } else {
        Toast.fail(data.msg);
      }

      console.log("登录返回值---", data);
    };

    const getUserInfo = async () => {
      const { data } = await getInfo();
      localStorage.setItem("info", JSON.stringify(data));
    };
    return {
      form,
      onSubmit,
      route,
    };
  },
});
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100vh;
  position: relative;
  background-color: #faf9f6;
  color: var(--textColor);

  img {
    width: 100%;
  }

  .contentText {
    position: absolute;
    z-index: 2;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;
    padding: 0 3%;

    img {
      margin: 0 auto;
      width: 200px;
      height: 70px;
    }

    .title {
      font-size: 2.1rem;
      font-weight: 800;
      letter-spacing: 2px;
      text-align: center;
      margin: 40px 0;
    }

    .form {
      .van-cell {
        background-color: transparent;
        transition: all 0.5s;
      }
      .van-cell::after {
        border-bottom: 1px solid #caa674;
      }
      /deep/ .van-field__label {
        color: var(--textColor);
      }
      /deep/ .van-field__control {
        color: var(--textColorTwo);
      }
      /deep/ .van-field__left-icon {
        font-size: 50px;
        color: #caa674;
      }
      /deep/ .van-field__control {
        padding-left: 20px;
      }
      /deep/ .van-button__text {
        font-size: 1.2rem;
      }

      .myButton {
        background-color: #caa674;
        border-radius: 0;
        border: none;
        height: 60px;
        letter-spacing: 5px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #fff;
        margin-top: 40px;
      }
    }

    .text {
      margin-top: 40px;
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #caa674;
      text-align: center;
    }
  }
}
</style>
